home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / misc / emu / stlist.lha / stlist / stlist.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-06  |  2.3 KB  |  92 lines

  1. /* Atari .ST diskimages list  */
  2. /* Fabrizio "Lanch" Bartoloni */
  3. /*   lanch@tiscalinet.it      */
  4. /*
  5.  Thanks to: Alfonso "Alfie" Ranieri
  6.             Emiliano "Skywalk3r" Esposito
  7.             Alessandro "Crusher" Gatti
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13.  
  14. static char verstr[] = "$VER: STList 1.4 (05.11.00)";
  15.  
  16. int main(int argc, char **argv)
  17. {
  18. char *progname = argv[0];
  19. char *destfile = argv[2];
  20. FILE *fp, *fd;
  21. char *diskimage = argv[1];
  22. char buf[] = "               "; /* filenames are 12 characters long */
  23.                                 /* and they fill the whole space */
  24.                                 /* then 4 empty + 16 trash and repeat */
  25.  
  26.  
  27. if (argc != 3)
  28.  {
  29.  fprintf(stderr, " Usage: %s diskimage.st diskcontent.txt \n", progname);
  30.  fprintf(stderr, " © 2000 Fabrizio 'Lanch' Bartoloni \n");
  31.  fprintf(stderr, " lanch@tiscalinet.it \n");
  32.  exit(1);
  33.  }
  34.  
  35. if (fp = fopen(diskimage,"rb")) {
  36. /* We go to 0x0E00, here is located the beginning      */
  37. /* of the directory listing, else it must be at 0x1600 */
  38. long offset;
  39. int ascii;
  40. int ascii2;
  41. long increase;
  42.  
  43.  
  44. offset = 0x0E00L;
  45. fseek(fp,offset,0);
  46. ascii = fgetc(fp);
  47. if ((ascii > 49)&&(ascii < 123))
  48.  
  49.  {
  50.  offset = 0x0DE0L; /* we went one step before for the loop sake */
  51.  }
  52.  
  53. else
  54.  
  55.  {
  56.  offset = 0x15E0L;
  57.  fseek(fp,offset,0);
  58.  ascii2 = fgetc(fp);
  59.  if ((ascii2 < 49)|(ascii2 > 122))
  60.     {
  61.     fprintf(stderr, " %s ST diskimage is not DOS \n", diskimage);
  62.     exit(1);
  63.     }
  64.  }
  65. increase = 32L;
  66.  if (fd = fopen(destfile, "w")) {
  67. fprintf(fd, " Listing of %s :\n\n", diskimage);
  68. while (*buf != 0) {      /* until we don't find an empty buffer */
  69.  offset = offset + increase;
  70.  fseek(fp,offset,0);
  71.  fgets(buf, sizeof(buf), fp);
  72.  fprintf(fd," %s\n", buf);
  73.                   } /* endwhile */
  74. fprintf(fd,"\n End of listing.\n");
  75. exit(0);
  76.                                } /* endif fopen write */
  77.                              else
  78.                              {
  79.                              fprintf(stderr," Unable to create %s\n", destfile);
  80.                              exit(1);
  81.                              }
  82.                                 } /* endif fopen read */
  83.               else
  84.                   {
  85.                   fprintf(stderr, "Unable to open file: %s\n", diskimage);
  86.                   exit(1);
  87.                   }
  88. fclose(fd);
  89. fclose(fp);
  90. return(0);
  91.  }
  92.